#include <iostream>
#include <vector>
#include <string>
#include <iomanip> 
#include <project_config.h>

using namespace std;

void config_console(string abs) {
    jmap config("");
    config.load(abs+"/config/config.jmap");
    cout << "[Config]" << endl;
    int i = 0;
    map<string,string> map = config.to_cpp_map();

    size_t maxKeyLength = 0;
    size_t maxValueLength = 0;
    for (const auto& pair : map) {
        if (pair.first.length() > maxKeyLength) {
            maxKeyLength = pair.first.length();
        }
        if (pair.second.length() > maxValueLength) {
            maxValueLength = pair.second.length();
        }
    }


    for (std::map<string, std::string>::iterator it = map.begin(); it != map.end(); ++it) {
        if (it->first == "") {
            continue;
        }
        std::cout << "- " << std::left << std::setw(maxKeyLength) << it->first
                  << " 值=" << std::setw(maxValueLength) << it->second
                  << " |序列:" << std::setw(3) << i // 假设i不会超过999
                  << " ." << std::endl;
                i++;
    }
    cout << "\n[INFO] 指定名称的配置在下面输入名称，例如 default_thread\n" << endl;
    string key = trim(input("修改的配置选项名称: "));
    string value = trim(input("配置选项分配的值: "));

    map[key] = value;
    write_to_file(abs+"/config/config.jmap"  , config.mapToString(map) , "w");
    cout << "[OK] 修改成功!" << endl;
}